package core;

import client.TankClient;
import entity.BaseTank;
import entity.Bullet;
import map.GMap;
import map.GMapType;

import java.util.ArrayList;
import java.util.List;

/**
 * 坦克大战核心类
 * @author lijia
 *
 */
public class TankCore {

	private static final int DEFAULT_CLIENT_NUMBER = 10;
	private List<BaseTank> tanks = new ArrayList<>();
	private List<Bullet> bullets = new ArrayList<>();
	private StartLineCore startLineCore = null;
	private int playerNumber;
	/**
	 *	地图
	 */
	private GMap map;
	
	private TankCore() {}
	
	public static TankCore getInstance() {
		TankCore core = new TankCore();
		core.initStartLine();
		return core;
	}
	
	public static TankCore getPreparedInstance(int number, GMap map) {
		TankCore core = new TankCore();
		core.initStartLine(number);
		core.initMap(map);
		return core;
	}
	
	public void initMap(GMap map) {
		this.map = map;
	}
	
	private void initStartLine() {
		initStartLine(DEFAULT_CLIENT_NUMBER);
	}
	
	private void initStartLine(int number) {
		this.playerNumber = number;
		if(startLineCore == null) {
			startLineCore = new StartLineCore(this);
		}
		startLineCore.init(this);
	}

	public int getPlayerNumber() {
		return playerNumber;
	}

	public void setPlayerNumber(int playerNumber) {
		this.playerNumber = playerNumber;
	}
	
	public void startGameInform(TankClient client) {
		
	}
	
	public void getClient(TankClient client) {
		this.startLineCore.join(client);
	}
	
	public void startGame(StartLineCore startLine) {
		System.out.println("所有玩家都已经准备好了，游戏开始！");
		startLine.start();
	}
	
	public static void main(String[] args) {
		TankCore core = TankCore.getPreparedInstance(2,GMap.getMap(GMapType.SCHOOL));
		TankClient client1 = new TankClient();
		TankClient client2 = new TankClient();
		core.getClient(client1);
		core.getClient(client2);
	}
	
}
